<template>
  <div>

    <el-form :inline="true" size="mini">
      <el-form-item :label="`导出数据`">
        <el-button-group>
          <el-button type="primary" size="mini" :disabled="currentTableData.length === 0" @click="handleDownloadXlsx(currentTableData)">
            xlsx
          </el-button>
        </el-button-group>
      </el-form-item>
    </el-form>

    <el-table :data="currentTableData" :summary-method="getSummaries" show-summary v-loading="loading" size="mini"
      stripe style="width: 100%;">
      <el-table-column label="登记日期" align="center" fixed>
        <template slot-scope="scope">
          {{scope.row.regDate}}
        </template>
      </el-table-column>
      <el-table-column label="单位" align="center" fixed>
        <template slot-scope="scope">
          {{scope.row.schoolName}}
        </template>
      </el-table-column>

      <el-table-column label="类型" align="center" fixed>
        <template slot-scope="scope">
          {{scope.row.typeName}}
        </template>
      </el-table-column>

      <el-table-column label="年级" align="center" fixed>
        <template slot-scope="scope">
          {{scope.row.gradeName}}
        </template>
      </el-table-column>

      <el-table-column label="已复学班级数" align="center">
        <template slot-scope="scope">
          {{scope.row.classNum}}
        </template>
      </el-table-column>

      <el-table-column label="学生应到数" align="center">
        <el-table-column label="2019年秋季定案数" :show-overflow-tooltip="true" align="center">
          <template slot-scope="scope">
            {{scope.row.planStdentNum}}
          </template>
        </el-table-column>

        <el-table-column label="转入" :show-overflow-tooltip="true" align="center">
          <template slot-scope="scope">
            {{scope.row.comeinNum}}
          </template>
        </el-table-column>

        <el-table-column label="转出" align="center">
          <template slot-scope="scope">
            {{scope.row.comeoutNum}}
          </template>
        </el-table-column>

        <el-table-column label="事假" :show-overflow-tooltip="true" align="center">
          <template slot-scope="scope">
            {{scope.row.absentNum}}
          </template>
        </el-table-column>

      </el-table-column>

      <el-table-column label="教职工复工人数" :show-overflow-tooltip="true" align="center">
        <template slot-scope="scope">
          {{scope.row.teacherNum}}
        </template>
      </el-table-column>

      <el-table-column label="学生实到数" :show-overflow-tooltip="true" align="center">
        <template slot-scope="scope">
          {{scope.row.factStdentNum}}
        </template>
      </el-table-column>
      <el-table-column label="因病缺课、发热等异常人员追踪诊断情况" align="center">


        <el-table-column label="疑似新冠肺炎人数" :show-overflow-tooltip="true" align="center">
          <template slot-scope="scope">
            {{scope.row.suspectedNum}}
          </template>
        </el-table-column>
        <el-table-column label="其他传染病人数" :show-overflow-tooltip="true" align="center">
          <template slot-scope="scope">
            {{scope.row.otherInfectNum}}
          </template>
        </el-table-column>
        <el-table-column label="其他疾人数" :show-overflow-tooltip="true" align="center">
          <template slot-scope="scope">
            {{scope.row.otherCaseNum}}
          </template>
        </el-table-column>
        <el-table-column label="待诊断人数" :show-overflow-tooltip="true" align="center">
          <template slot-scope="scope">
            {{scope.row.infectionNum}}
          </template>
        </el-table-column>
        <el-table-column label="居家隔离" :show-overflow-tooltip="true" align="center">
          <template slot-scope="scope">
            {{scope.row.stayNum}}
          </template>
        </el-table-column>
        <el-table-column label="备注" :show-overflow-tooltip="true" align="center">
          <template slot-scope="scope">
            {{scope.row.dateTimeUse}}
          </template>
        </el-table-column>
        <el-table-column label="小计" :show-overflow-tooltip="true" align="center">
          <template slot-scope="scope">
            {{scope.row.remark}}
          </template>
        </el-table-column>
      </el-table-column>
    </el-table>
  </div>
</template>

<script> 
  export default { 
    props: {
      tableData: {
        default: () => []
      },
      loading: {
        default: false
      }
    },
    data() {
      return {
        currentTableData: []
      }
    },
    watch: {
      tableData: {
        handler(val) {
          this.currentTableData = val
        },
        immediate: true
      }
    },
    methods: {

      getSummaries(param) {
        const {
          columns,
          data
        } = param;
        const sums = [];
        columns.forEach((column, index) => {
          if (index === 0) {
            sums[index] = '即时合计（只含初中、高中、职高）';
            return;
          }
          const values = data.map(item => Number(item[column.property]));
          // if (!values.every(value => isNaN(value))) {
          if (true) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr);
              if (!isNaN(value)) {
                return prev + 1;
              } else {
                return 1;
              }
            }, 0);
            sums[index] += ' 人';
          } else {
            sums[index] = 'N/A';
          }
        });
        return sums;
      },
      handleSwitchChange(val, index) {
        const oldValue = this.currentTableData[index]
        this.$set(this.currentTableData, index, {
          ...oldValue,
          type: val
        })
        // 注意 这里并没有把修改后的数据传递出去 如果需要的话请自行修改
      },
      handleDownloadXlsx(data) {
        this.$message('导出表格成功')
      }
    }
  }
</script>
